package com.hyou.demos.mybatis.web.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyou.demos.mybatis.base.CommonMessage;
import com.hyou.demos.mybatis.pojo.DemoUser;
import com.hyou.demos.mybatis.service.DemoUserService;

@RestController("demoController")
@RequestMapping("/demo")
public class DemoController {
    
    private static final Logger log = LoggerFactory.getLogger(DemoController.class);
    
    @Resource(name = "demoUserService")
    private DemoUserService demoUserService;
    
    @RequestMapping(path = "/list/{offset}/{limit}")
    public CommonMessage list(@PathVariable("offset") int offset, @PathVariable("limit") int limit) {
        log.debug("param : offset=[{}], limit=[{}]", offset, limit);
        
        List<DemoUser> list = demoUserService.selectByPage(null, offset, limit);
        return new CommonMessage(true, "ok", list);
    }
    
    @RequestMapping(path = "/list2")
    public CommonMessage list2(HttpServletRequest request) {
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        log.debug("param : offset=[{}], limit=[{}]", offset, limit);
        
        List<DemoUser> list = demoUserService.selectByPage(null, Integer.valueOf(offset), Integer.valueOf(limit));
        return new CommonMessage(true, "ok", list);
    }
    
}
